package com.saurshaz.testmvc;

import java.util.List;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.QueryHint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooEntity(versionField = "", table = "nodes", schema = "dynamictree")
@RooDbManaged(automaticallyDelete = true)
@Entity
@Cacheable
@Cache(region = "node", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@NamedQueries({
		@NamedQuery(name = "selectAllNodes", query = "Select o FROM Node o"),
		@NamedQuery(name = "findAllParentNodes", query = "Select o FROM Node o where o.isParent = '1'"),
		@NamedQuery(name = "findByParentNodeId", query = "Select o FROM Node o where o.isParent = '0' AND  o.nodeParentId = :nodeParentId") })
public class Node {
	public static List<Node> findAllNodes() {
		return entityManager().createNamedQuery("selectAllNodes", Node.class)
				.getResultList();
	}
	
	public static List<Node> findAllParentNodes() {
		return entityManager().createNamedQuery("selectAllParentNodes", Node.class)
				.getResultList();
	}

	public static List<Node> findByParentNodeId(Long nodeParentId) {
		return entityManager()
				.createNamedQuery("findByParentNodeId", Node.class)
				.setParameter("nodeParentId", nodeParentId).getResultList();
	}
}
